<?php

namespace App\Http\ViewComposers;

use Illuminate\Contracts\View\View;

class TopNavComposers{

    /**
     * 顶部导航数据
     */
    public function compose(View $view){

        $nav = [
            'common' => [
                ['name' => '首页', 'url' => url('/')]
            ],
            'login_before' => [
                ['name' => '登录', 'url' => url('/login')],
                ['name' => '注册', 'url' => url('/register')],
            ],
            'login_after' => []
        ];
        if (\Auth::check()){
            $nav['login_after'] = [
                ['name' => \Auth::user()->name, 'url' => url('/user')],
                ['name' => '设置', 'url' => url('/user/setting')],
                ['name' => '退出', 'url' => url('/logout')],
            ];
        }

        $view->with('top_nav', $nav);
    }
}